package org.ttitfly.zuoyue.entity.attachment;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.ttitfly.ttcore.entity.IdEntity;


/**
 * 附件
 * 
 * @author panhaichun
 * 
 */
@Entity
@Table(name = "ATTACHMENT")
public class Attachment extends IdEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Column(name = "NAME")
	private String name;

	@Column(name = "PATH")
	private String path;

	@Column(name = "SIZE")
	private Long size;

	@Column(name = "UPLOAD_TIME")
	private Date uploadTime;

	@Column(name = "USERNAME")
	private String username;
	
	@Column(name = "CONTENT_TYPE")
	private String contentType = "text/plain";
	
	@Transient
	private File file;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public Long getSize() {
		return size;
	}

	public void setSize(Long size) {
		this.size = size;
	}

	public Date getUploadTime() {
		return uploadTime;
	}

	public void setUploadTime(Date uploadTime) {
		this.uploadTime = uploadTime;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getContentType() {
		return contentType;
	}

	public void setContentType(String contentType) {
		this.contentType = contentType;
	}

	@Transient
	public File getFile() {
		return file;
	}

	@Transient
	public void setFile(File file) {
		this.file = file;
	}
	
	@Transient
	public InputStream getDownloadInputStream() throws FileNotFoundException {
		return new FileInputStream(file);
	}
	
}
